﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace UI.Forms
{
    public partial class whd_d_ld : FormBase1
    {
        BindingList<SVC.client.View_Emp_lite> emps;
        BindingList<SVC.client.get_whd_View_allResult> vds;
        public whd_d_ld()
        {
            InitializeComponent();
        }

        private void whd_d_ld_Load(object sender, EventArgs e)
        {
            vds = new BindingList<SVC.client.get_whd_View_allResult>();
            emps = my.bw.View_Emp_lite_List("", my.ACID);
            lue_ldr.Properties.DataSource=emps;
            lue_ldr.EditValue = my.emp_lite.EmplID;
            gridControl1.DataSource = vds;
        }

        private void btn_load_Click(object sender, EventArgs e)
        {   
            vds.Clear();
            foreach (SVC.client.get_whd_View_allResult item in my.bw.getwhd_view_allresult(my.emp_lite.EmpName, 4, my.ACID))
            {
                vds.Add(item);
            }
            
        }

        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            if (e.Button == MouseButtons.Left && e.Clicks == 2)
            {
                if (e.RowHandle >= 0)
                {
                    
                    SVC.client.get_whd_View_allResult vd = gridView1.GetRow(e.RowHandle) as SVC.client.get_whd_View_allResult;
                    if (vd == null) return;
                    te_did.Text = vd.编号.ToString();
                    lue_ldr.EditValue = my.emp_lite.EmplID;
                }
            }
        }

        private void btn_save_Click(object sender, EventArgs e)
        {
            if (!dvp.Validate()) return;
            SVC.client.whd_d_fk fk = my.bw.whd_d_fkBydid_Get(int.Parse(te_did.Text), my.ACID);
            if (fk==null)
            {
                Comm.ShowErorr("无效编号！");
            }
            else
            {
                string r = my.bw.ld(fk, 5, my.ACID);
                if (string.IsNullOrEmpty(r))
                {
                    Comm.ShowInfo("保存数据成功！");
                    resetEditor();
                }
                else
                {
                    Comm.ShowErorr(r);
                }
                        
            }
                        
        }

        private void resetEditor()
        {
            vds.Remove(vds.Single(p => p.编号 == int.Parse(te_did.Text)));
            te_did.Text = "";
            sp_ldjfje.EditValue = 0;
            me_gdbz.Text = "";
            me_xcsj.Text = "";
        }

        private void btn_print_Click(object sender, EventArgs e)
        {
            gridControl1.ShowPrintPreview();
        }
    }
}